-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
convert between integer and byte array #103
Conversation
Tests seem crashed at
|
The PR seems to have gone fallow, but if you come back to it, it'd be great to extend this to the float types as they also got these methods in 1.40. |
Hi @erikbrinkman and @cuviper The PR has be updated
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Bytes
implemented so generically, this could also support types like BigUint
using Vec<u8>
. Consuming self
is not desirable in that case, so maybe the trait should use &self
in the to_
methods? And likewise for from_
, should they take &Self::Bytes
? I expect the references would also get optimized away for the primitive cases anyway.
We do need to drop the breaking changes to existing traits. I would also like to see unit tests that cover each of the implemented primitive types.
src/float.rs
Outdated
|
||
#[cfg(all(not(feature = "std"), feature = "libm"))] | ||
use libm; | ||
|
||
/// Generic trait for floating point numbers that works with `no_std`. | ||
/// | ||
/// This trait implements a subset of the `Float` trait. | ||
pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy { | ||
pub trait FloatCore: Num + NumCast + Neg<Output = Self> + PartialOrd + Copy + ToFromBytes { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a breaking change to add requirements to the existing traits. ToFromBytes
will have to stand alone.
src/int.rs
Outdated
@@ -51,6 +51,7 @@ pub trait PrimInt: | |||
+ CheckedMul<Output = Self> | |||
+ CheckedDiv<Output = Self> | |||
+ Saturating | |||
+ ToFromBytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also a breaking change.
498f7d8
to
fe7d50d
Compare
Co-authored-by: Flier Lu <flier.lu@gmail.com>
efa9f80
to
a922693
Compare
Sorry, I pushed to this branch on accident, but the revived development is in #224. |
After Rust 1.32, the function
to_<endian>_bytes
andfrom_<endian>_bytes
has stabilizations.